import  fetchRequest from '@/util/fetch'
import {
	isEmpty,
	isNotEmpty,
	deepClone,
	UUIDGeneratorBrowser
} from '@/util/localTool'
const SERVICE = "/blade-system"
import {store} from '@/stores/allStores'
// 获取上传文件的token
export const safeTokenUploadSystemApi = (fileMD5: any, fileName: any, filingTime: any) => {
	return fetchRequest({
		url: SERVICE + '/api/upload/token/safe',
		method: 'get',
		params: {
			fileMD5: fileMD5,
			fileName: fileName,
			filingTime: filingTime
		},
		carryToken: 2
	})
}

export const fileUploadSystemApi = (filePath: any, formData: any) => {
	interface headType {
		[key: string] :any
	}
	let header:headType = {}
	if (isNotEmpty(store.user.token)) {
		header['Blade-Auth'] = 'bearer ' + store.user.token
	}
	if (isNotEmpty(store.user.xcxAppId)) {
		header['xcx-app-id'] = store.user.xcxAppId
	}
	if (isNotEmpty(store.user.mpAppId)) {
		header['mp-app-id'] = store.user.mpAppId
	}
	if (isNotEmpty(store.user.tenantId)) {
		header['tenant-id'] = store.user.tenantId
	}

	header['Authorization'] = 'Basic c2FiZXI6c2FiZXJfdGJrX3NlY3JldA=='
	header['trace-id'] = UUIDGeneratorBrowser().replace(/-/g, '')
	header['trace-soft-info'] = store.app.appName + ':' + store.app.appVersion

	return new Promise((resolve, reject) => {
		let baseUrl = store.app.baseUrlList[0]
		/*
		uni.uploadFile({
			url: baseUrl + SERVICE + '/api/upload/file',
			name: 'file',
			dataType: "json",
			header: header,
			formData: formData,
			filePath: filePath,
			success: function(res: { data: string }) {
				let data = JSON.parse(res.data)
				if (data.code === 200) {
					resolve(data.data)
				} else {
					reject(data)
				}

			},
			fail: (err: any) => {
				reject(err)
			}
		})
		*/
	})
}

// 获取字典
export const mapDataDictSystemApi = (codes:any) => {
	return fetchRequest({
		url: SERVICE + '/api/dict/mapData',
		method: 'get',
		params: {
			codes:codes
		},
		carryToken: 2
	})
}

// 获取地区
export const treeTmVuetifyRegionApi = (level: any) => {
	return fetchRequest({
		url: SERVICE + '/api/region/tmVuetify/tree',
		method: 'get',
		params: {
			level: level,
		},
		carryToken: 2
	})
}


export const saveSystemCacheApi = (data: any) => {
	return fetchRequest({
		url: SERVICE + '/api/systemCache/save',
		method: 'post',
		data: data
	})
}

export const detailSystemCacheApi = (value: any) => {
	return fetchRequest({
		url: SERVICE + '/api/systemCache/detail',
		method: 'get',
		params: {
			typeEnum: value,
		}
	})
}
export const removeSystemCacheApi = (value: any) => {
	return fetchRequest({
		url: SERVICE + '/api/systemCache/remove',
		method: 'post',
		params: {
			typeEnum: value,
		}
	})
}
export const updateUserApi = (data: any) => {
	return fetchRequest({
		url: SERVICE + '/api/user/update',
		method: 'post',
		data: data
	})
}
export const myUserApi = (data: any = {}) => {
	return fetchRequest({
		url: SERVICE + '/api/user/my',
		method: 'get'
	})
}
export const detailUserApi = (params: any = {}) => {
	return fetchRequest({
		url: SERVICE + '/api/user/detail',
		method: 'get',
		params: params
	})
}

export const paramsSystemAppApi = (params: any) => {
	return fetchRequest({
		url: SERVICE + '/api/systemApp/params',
		method: 'get',
		params: params,
		carryToken: 2
	})
}

export const homeDisplaySystemNoticeApi = (params: any) => {
	return fetchRequest({
		url: SERVICE + '/api/systemNotice/homeDisplay',
		method: 'get',
		params: params,
		carryToken: 2
	})
}


export const detailSystemAppApi = () => {
	return fetchRequest({
		url: SERVICE + '/api/systemApp/detail',
		method: 'get',
		carryToken: 2
	})
}

export const saveSystemFeedbackApi = (data: any) => {
	return fetchRequest({
		url: SERVICE + '/api/systemFeedback/save',
		method: 'post',
		data: data
	})
}


export const listSystemUserMsgApi = (params: any) => {
	return fetchRequest({
		url: SERVICE + '/api/systemUserMsg/list',
		method: 'get',
		params: params
	})
}



export const removeSystemUserMsgApi = (ids: any) => {
	return fetchRequest({
		url: SERVICE + '/api/systemUserMsg/remove',
		method: 'post',
		params: {
			ids: ids
		}
	})
}


export const unReadStatisticsSystemUserMsgApi = (subjectEnums: any) => {
	return fetchRequest({
		url: SERVICE + '/api/systemUserMsg/statistics/unRead',
		method: 'get',
		params: {
			subjectEnums: subjectEnums
		}
	})
}

export const detailByTypeEnumSystemPageApi = (typeEnum: any) => {
	return fetchRequest({
		url: SERVICE + '/api/systemPage/detailByTypeEnum',
		method: 'get',
		params: {
			typeEnum: typeEnum
		}
	})
}

export const detailSystemPageApi = (id: any) => {
	return fetchRequest({
		url: SERVICE + '/api/systemPage/detail',
		method: 'get',
		params: {
			id: id
		},
		carryToken: 2
	})
}


export const listSystemWalletRecordApi = (params: any) => {
	return fetchRequest({
		url: SERVICE + '/api/systemWalletRecord/list',
		method: 'get',
		params: params
	})
}



export const withdrawalApplyUserApi = (data: any) => {
	return fetchRequest({
		url: SERVICE + '/api/user/withdrawalApply',
		method: 'post',
        data: data
	})
}

export const rechargeUserApi = (data: any) => {
	return fetchRequest({
		url: SERVICE + '/api/user/recharge',
		method: 'post',
        data: data
	})
}
export const saveShareRecordUserApi = (params: any) => {
	return fetchRequest({
		url: SERVICE + '/api/user/shareRecord/save',
		method: 'post',
        params: params
	})
}

